package com.sky.yipinyoufujava.service.imp;

import com.sky.yipinyoufujava.mapper.LoginMapper;
import com.sky.yipinyoufujava.pojo.WxUserInfo;
import com.sky.yipinyoufujava.pojo.from.LoginForm;
import com.sky.yipinyoufujava.pojo.from.ModifyPasswordForm;
import com.sky.yipinyoufujava.pojo.from.RegisterForm;
import com.sky.yipinyoufujava.pojo.User;
import com.sky.yipinyoufujava.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImp implements LoginService {
    @Value("${spring.mail.username}")
    private String ownEmail;
    @Autowired
    private LoginMapper loginMapper;
    @Autowired
    private JavaMailSender javaMailSender;
    @Override
    public User login(LoginForm loginForm) {
        return loginMapper.getUser(loginForm);
    }

    @Override
    public Short queryUser(String name) {
        return loginMapper.queryUser(name);
    }

    @Override
    public void registerUser(RegisterForm registerForm) {
        loginMapper.registerUser(registerForm);
    }

    @Override
    public User queryUserId(Object id) {
        return loginMapper.queryUserId(id);
    }




    @Override
    public void sentEmail(String userEmail, String msg, String context) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();

        simpleMailMessage.setFrom("1769705138@qq.com");
        simpleMailMessage.setTo(userEmail);
        simpleMailMessage.setSubject(msg);
        simpleMailMessage.setText(context);
//        发送邮箱
        javaMailSender.send(simpleMailMessage);
    }

    @Override
    public void modifyPassword(int id, ModifyPasswordForm modifyPasswordForm) {
        loginMapper.modifyPassword(id,modifyPasswordForm);
    }

    @Override
    public void updataUserInfo(User user) {
        loginMapper.updataUserInfo(user);
    }

    @Override
    public User queryUserByOpenId(String phone) {
        return loginMapper.queryUserByOpenId(phone);
    }

    @Override
    public void wxRegister(WxUserInfo wxUserInfo) {
        loginMapper.wxRegister(wxUserInfo);
    }


}
